package AsLayers.Layer
{	import AsLayers.BaseType.Bounds;
import AsLayers.BaseType.Pixel;
import AsLayers.Map;
import AsLayers.Tile.Feature;
import AsLayers.Tile.ITile;

import mx.containers.Canvas;
	public class Feature extends Grid
	{
		public var name:String
		public var url:String
		private var serviceUrl:String
		public  var container:Canvas=new Canvas();
		public var config={
			 layers:""
		}
		public function Feature(name:String,url:String,config:Object)
		{
			super();
			this.name=name;
			this.url=url;
			this.config=config;
			this.serviceUrl=this.url+"?type=contains&layers="+this.config.layers+"&shape=";
		}
		override public function setMap(map:Map):void{
			this.container.clipContent=false
			map.getLayerContainer().addChildAt(this.container,map.getLayerContainer().getChildren().length-1);
      
			super.setMap(map);
		//	trace(map.getLayerContainer().width)
			//this.container
			

		}
		override public function getUrl(bounds:Bounds):String{
			//var w:Number=this.getTileSize().w;
			//var h:Number=this.getTileSize().h;
			var p1:String=bounds.left+" "+bounds.bottom
			var p2:String=bounds.left+" "+bounds.top
			var p3:String=bounds.right+" "+bounds.top
			var p4:String=bounds.right+" "+bounds.bottom
			var shape:String="POLYGON(("+p1+","+p2+","+p3+","+p4+","+p1+"))";
			return this.serviceUrl+shape;
		}
		override public function addTile(bounds:Bounds,position:Pixel):ITile{
			
			var tile:AsLayers.Tile.Feature=new AsLayers.Tile.Feature(position,bounds,this.getTileSize());
			tile.setLayer(this);
			this.container.addChild(tile.display);
			return tile;
		}
	}
}